package com.lemon.smartsafety.utils.app;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.TextView;
import android.widget.Toast;

import com.lemon.smartsafety.R;

/**
 * Created by Cooliean on 16/1/20.
 */
public class ToastUtil {
    private static Toast sToast;
    private static TextView sMsgTv;
    private static Context mContext;

    private ToastUtil() {
    }

    private ToastUtil(Context context) {
        this.mContext = context;
    }

    public static void init(Context context) {
        sToast = new Toast(context);
        sToast.setGravity(Gravity.CENTER, 0, 0);
        sMsgTv = (TextView) LayoutInflater.from(context).inflate(R.layout.item_textview, null);
        sToast.setView(sMsgTv);
        sToast.setDuration(Toast.LENGTH_SHORT   );
    }


    /**
     * 短时间显示
     */
    public static  void showShort(){
        try {
            sToast.setDuration(Toast.LENGTH_SHORT);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 长时间显示
     */
    public static  void showLong(){
        try {
            sToast.setDuration(Toast.LENGTH_LONG);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void show(CharSequence text) {
        try {
            if(sMsgTv!=null) {
                sMsgTv.setText(text);
                sToast.show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
